package com.novell.sasl.client;

import org.apache.harmony.javax.security.sasl.SaslException;

class TokenParser
{
  private static final int STATE_LOOKING_FOR_FIRST_TOKEN = 1;
  private static final int STATE_LOOKING_FOR_TOKEN = 2;
  private static final int STATE_SCANNING_TOKEN = 3;
  private static final int STATE_LOOKING_FOR_COMMA = 4;
  private static final int STATE_PARSING_ERROR = 5;
  private static final int STATE_DONE = 6;
  private int m_curPos;
  private int m_scanStart;
  private int m_state;
  private String m_tokens;

  TokenParser(String paramString)
  {
    this.m_tokens = paramString;
    this.m_curPos = 0;
    this.m_scanStart = 0;
    this.m_state = 1;
  }

  String parseToken()
    throws SaslException
  {
    String str = null;
    if (this.m_state == 6)
      return null;
    while ((this.m_curPos < this.m_tokens.length()) && (str == null))
    {
      char c = this.m_tokens.charAt(this.m_curPos);
      switch (this.m_state)
      {
      case 1:
      case 2:
        if (!isWhiteSpace(c))
          if (isValidTokenChar(c))
          {
            this.m_scanStart = this.m_curPos;
            this.m_state = 3;
          }
          else
          {
            this.m_state = 5;
            throw new SaslException("Invalid token character at position " + this.m_curPos);
          }
        break;
      case 3:
        if (!isValidTokenChar(c))
          if (isWhiteSpace(c))
          {
            str = this.m_tokens.substring(this.m_scanStart, this.m_curPos);
            this.m_state = 4;
          }
          else if (',' == c)
          {
            str = this.m_tokens.substring(this.m_scanStart, this.m_curPos);
            this.m_state = 2;
          }
          else
          {
            this.m_state = 5;
            throw new SaslException("Invalid token character at position " + this.m_curPos);
          }
        break;
      case 4:
        if (!isWhiteSpace(c))
          if (c == ',')
          {
            this.m_state = 2;
          }
          else
          {
            this.m_state = 5;
            throw new SaslException("Expected a comma, found '" + c + "' at postion " + this.m_curPos);
          }
        break;
      }
      this.m_curPos += 1;
    }
    if (str == null)
      switch (this.m_state)
      {
      case 3:
        str = this.m_tokens.substring(this.m_scanStart);
        this.m_state = 6;
        break;
      case 1:
      case 4:
        break;
      case 2:
        throw new SaslException("Trialing comma");
      }
    return str;
  }

  boolean isValidTokenChar(char paramChar)
  {
    return ((paramChar < 0) || (paramChar > ' ')) && ((paramChar < ':') || (paramChar > '@')) && ((paramChar < '[') || (paramChar > ']')) && (',' != paramChar) && ('%' != paramChar) && ('(' != paramChar) && (')' != paramChar) && ('{' != paramChar) && ('}' != paramChar) && ('' != paramChar);
  }

  boolean isWhiteSpace(char paramChar)
  {
    return ('\t' == paramChar) || ('\n' == paramChar) || ('\r' == paramChar) || (' ' == paramChar);
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     com.novell.sasl.client.TokenParser
 * JD-Core Version:    0.6.1
 */